﻿using System;
using System.Configuration;
using System.ServiceModel;
using QuailServices.QuailTestRunnerServiceReference;

namespace QuailServices
{
    /// <summary>
    /// Wraps construction of the QuailTestRunnerClient object
    /// </summary>
    public static class QuailTestRunnerFactory
    {
        /// <summary>
        /// Creates a new instance of the QuailTestRunnerClient
        /// </summary>
        /// <returns>A new QuailTestRunnerClient</returns>
        public static QuailTestRunnerClient CreateClient()
        {
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
                              {
                                  ReaderQuotas =
                                      {
                                          MaxArrayLength = 20000000,
                                          MaxStringContentLength = 20000000
                                      },
                                  SendTimeout = new TimeSpan(0, 10, 0),
                                  ReceiveTimeout = new TimeSpan(0, 10, 0),
                                  MaxReceivedMessageSize = 50000000,
                                  MaxBufferSize = 50000000,
                              };

            var host = ConfigurationManager.AppSettings["TestRunnerService"] ?? "http://qaquailweb/QuailTestRunner.svc";
            var endpoint = new EndpointAddress(host);

            var result = new QuailTestRunnerClient(binding, endpoint);

            return result;
        }
    }
}
